import {
  Body,
  Controller,
  Get,
  Inject,
  Post,
  Provide,
  ALL,
  Param,
  Put,
  Query,
} from '@midwayjs/decorator';
import {
  CreateUserDto,
  GetUserInfoDao,
  UpdateUserDto,
} from '../../../dto/admin/sys/user';
import { UpdateUserRoleDto } from '../../../dto/admin/sys/userRole';
import { SysUserService } from '../../../service/admin/sys/user';
import { BaseContrall } from '../../base';

@Provide()
@Controller('/admin')
export class SysUserController extends BaseContrall {
  @Inject()
  sysUserService: SysUserService;

  @Get('/user')
  async getUserList() {
    const userList = await this.sysUserService.getUserList();
    return {
      code: 0,
      data: userList,
      msg: 'ok',
    };
  }
  @Get('/user:id')
  async getUserInfo(@Param('id') id: GetUserInfoDao) {
    const user = await this.sysUserService.getUserInfo(id);
    return {
      code: 0,
      data: user,
      msg: 'ok',
    };
  }
  @Post('/user')
  async createUser(@Body(ALL) user: CreateUserDto) {
    const data = await this.sysUserService.createUser(user);
    return {
      code: 0,
      data: data,
      msg: 'ok',
    };
  }

  @Get('/etUserAndrole')
  async getUserAndRole(@Query() id: number) {
    const list = await this.sysUserService.getUserAndRole(id);
    return {
      code: 0,
      data: list,
      msg: 'ok',
    };
  }
  @Put('/user')
  async updateUser(@Body(ALL) user: UpdateUserDto) {
    const data = await this.sysUserService.updateUser(user);
    return {
      code: 0,
      data: data,
      msg: 'ok',
    };
  }

  @Put('/userRole')
  async updateUserRole(@Body(ALL) userRole: UpdateUserRoleDto) {
    const data = await this.sysUserService.updateUserRole(userRole);
    return {
      code: 0,
      data: data,
      msg: 'ok',
    };
  }
}
